(** Functions for running subprocesses and processing their output. *)

(** Exception raised by run_subprocess if the command line is malformed. *)
exception BadCommandLine of string

(** Exception raised by run_subprocess when the subprocess exits with
    a non-zero exit status. *)
exception NonzeroExitStatusFailure of int

(** Exception raised by run_subprocess when the subprocess is killed
   or stopped by a signal. *)
exception SignalFailure of int

(** run_subprocess cmd_line stdout_reader stderr_reader killer_setter

    Runs a subprocess with callbacks to process its stdout and stderr,
    and returns when the subprocess has finished.  On success, returns
    unit.  On failure raises an exception.

    cmd_line is split by whitespace and used as the command-line.

    stdout_reader should consume the stdout channel that is passed to
    it, and then return when it reaches eof.  Similar for
    stderr_reader.  If stdout_reader or stderr_reader raises an
    exception, then the subprocess is killed prematurely and the
    exception is re-raised by run_subprocess itself.

    For example functions that can be used for stdout_reader and
    stderr_reader, see subprocess_test.ml.

    killer_setter is called with a function which, if invoked, will kill
    the subprocess.  *)
val run_subprocess : string -> (in_channel -> unit) ->
  (in_channel -> unit) -> ((unit -> unit) -> unit) -> unit
